import type { App, Component } from 'vue'
type AsyncComponentLoader = () => Promise<{ default: Component }>
// const modules = import.meta.glob('@/components/*.vue') as Record<string, AsyncComponentLoader>


// const loadModules = async () => {
//     return await Promise.all(
//         Object.keys(modules).map(async (key) => {
//             const module = await modules[key]();
//             return { key, module };
//         })
//     );
// };

export default {
    async install(app: App) {
        const modules = import.meta.glob('@/components/*.vue') as Record<string, AsyncComponentLoader>

        Object.keys(modules).map(async (key) => {
            const module = await modules[key]();
            const name = key.slice(key.lastIndexOf('/') + 1, key.lastIndexOf('.'))
            app.component(`${name}`, module.default)
        })
        // const results = await loadModules()
        // console.log(result);


        // loadModules().then((results) => {
        //     results.forEach(({ key, module }) => {
        //         const name = key.slice(key.lastIndexOf('/') + 1, key.lastIndexOf('.'))
        //         app.component(`${name}`, module.default)
        //     });
        // })
    }
}